package cn.tedu.shoot;

import java.awt.image.BufferedImage;

/*英雄机*/
public class Hero extends FlyingObject {
    private int life;/*生命*/
    private int fire;/*火力值*/
    private int hp = 100;
    private int index = 0;
    static final int WIDTH = 97;
    static final int HEIGHT = 139;
    public boolean shield = false;
    private int wSpeed = 0;
    private int sSpeed = 0;
    private int aSpeed = 0;
    private int dSpeed = 0;


    Hero(int x, int y) {
        super(WIDTH, HEIGHT);
        this.x = x;
        this.y = y;
        life = 3;
        fire = 5000;
    }

    public void step() {
        x += aSpeed;
        x += dSpeed;
        y += wSpeed;
        y += sSpeed;


    }

    public void setwSpeed(int a) {
        wSpeed = -a;
    }

    public void setsSpeed(int a) {
        sSpeed = a;
    }

    public void setaSpeed(int a) {
        aSpeed = -a;
    }

    public void setdSpeed(int a) {
        dSpeed = a;
    }

    //获取图片
    public BufferedImage getImage() {
        return Images.heros[index++ % Images.heros.length];
    }

    //子弹创建
    public Bullet[] shoot() {
        int xStep = this.width / 4;
        int yStep = -20;
        if (fire > 50) {
            Bullet[] bs = new Bullet[3];
            bs[0] = new Bullet(this.x + xStep - 4, this.y + yStep, -1);
            bs[1] = new Bullet(this.x + 2 * xStep - 4, this.y + yStep, 0);
            bs[2] = new Bullet(this.x + 3 * xStep - 4, this.y + yStep, 1);
            fire -= 2;
            return bs;
        } else if (fire > 0) {
            Bullet[] bs = new Bullet[2];
            bs[0] = new Bullet(this.x + xStep - 4, this.y + yStep, 0);
            bs[1] = new Bullet(this.x + 3 * xStep - 4, this.y + yStep, 0);
            fire -= 2;
            return bs;
        } else {
            Bullet[] bs = new Bullet[1];
            bs[0] = new Bullet(this.x + 2 * xStep - 4, this.y + yStep, 0);
            return bs;
        }
    }

    //英雄机移动
    public void moveTo(int x, int y) {
        this.x = x - this.width / 2;
        this.y = y - this.height / 2;
    }

    //英雄机获得火力
    public void addLife() {
        life++;
    }

    //英雄机获得生命
    public int getLive() {
        return life;
    }

    //英雄机失去生命
    public void subtractLife() {
        life--;
    }

    public void addHp() {
        hp = 100;
    }

    public void switchShield() {
        shield = !shield;
    }

    public void subtractHp() {
        hp -= 25;
    }

    public int getHp() {
        return hp;
    }


    public void clearFire() {
        fire = 0;
    }


    public void addFire() {
        fire += 40;
    }
}


